/**查看cmd帮助 
 * cmd命令 --help 或者 /?
 * @param {String} curAbsolutePath 使用此模块的文件绝对路径
 * @param {String} dirName 使用此模块的文件的目录
 * @param {Object} packageJson package.json文件内容
 */
Date.prototype.format = function (fmt) { //author: meizz   
    var o = {
        "M+": this.getMonth() + 1,                 //月份   
        "d+": this.getDate(),                    //日   
        "h+": this.getHours(),                   //小时   
        "m+": this.getMinutes(),                 //分   
        "s+": this.getSeconds(),                 //秒   
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
        "S": this.getMilliseconds()             //毫秒   
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
function showhelp(curAbsolutePath, dirName,packageJson) {
    let commentArg = process.argv.slice(2)[0];
    const { exec } = require('child_process');
    const path = require('path');
    if (commentArg !== '/?' && commentArg !==undefined) return
    const bin = packageJson.bin || {};
    let cmd = '';
    // 判断命令是否是当前文件的命令
    for (let i in bin) {
        if (path.resolve(curAbsolutePath, '') == path.resolve(dirName, bin[i])) {
            cmd = i;
            break
        }
    }
    // 打印 help 命令帮助
    exec(`${cmd} --help`, { shell: process.platform === 'win32' }, (error, stdout) => {
        if (error) {
            console.error(`执行出错: ${error}`);
            return;
        }
        console.log(stdout)
    })

    // console.log(packageJson.bin.test, __filename)
    // console.log(path.resolve(__filename, ''))
    // console.log(path.resolve(__dirname, packageJson.bin.test))
}

module.exports = {
    showhelp
}